<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_gm extends PNC_Model {
    /*
     * Show leave record type as catchup
     * @access public
     * @param int
     * @param int
     * @return array
     */

    public function show_catchup($per_page, $offset, $val_id, $status) {
        $query = $this
                ->db
                ->select('*')
                ->from('pnc_record')
                ->join('pnc_employee', 'pnc_employee.staff_id = pnc_record.staff_id')
                ->join('pnc_leave_type', 'pnc_leave_type.lea_id = pnc_record.lea_id')
                ->where('rcd_status', $status)
                ->where('val_id', $val_id)
                ->limit($per_page, $offset)
                ->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row_catchup) {
                $data[] = $row_catchup;
            }
            return $data;
        }
        return FALSE;
    }

    /* Select leaving request type */

    public function super_type_leave() {
        $this->db->select('*');
        $this->db->from('pnc_leave_type');
        $this->db->where('lea_id', 1);
        $querys = $this->db->get();
        return $querys;
    }

    /* Select sub type of leaving request */

    public function type_leave() {
        $this->db->select('*');
        $this->db->from('pnc_sub_leave');
        $querys = $this->db->get();
        $leave_type[0] = '--- Select one ---';
        foreach ($querys->result_array() as $row) {
            $leave_type[$row['stl_id']] = $row['stl_name'];
        }return $leave_type;
    }

    /* Select sub sub type of leaving request */

    public function sub_type_leave() {
        $this->db->select('*');
        $this->db->from('pnc_ss_leave');
        $querys = $this->db->get();
        $sub[0] = '--- Select one ---';
        foreach ($querys->result_array() as $row) {
            $sub[$row['ssl_id']] = $row['ssl_name'];
        }return $sub;
    }

    /* Count number of pending record */

    public function count_report_padding($val_id, $status) {
        $query = $this->db
                ->select('*')
                ->from('pnc_record')
                ->join('pnc_employee', 'pnc_record.staff_id = pnc_employee.staff_id')
                ->where('pnc_record.rcd_status', $status)
                ->where('pnc_record.val_id', $val_id)
                ->count_all_results();
        return $query;
    }

    /* Update status of record leaving approve */

    public function approve_update($id, $cur_status, $field, $table) {
        $data = '';
        if ($cur_status == 1) {
            $data = array($field => '0');
        } else {
            $data = array($field => '1');
        }
        $this->db->where('rcd_id', $id);
        return $this->db->update($table, $data);
    }

}
